package com.yyh.javase1;

import java.util.Arrays;

public class Demo3 {
    public static void main(String[] args) {
        String s1 = "12hello23-33word4";
        //将字符串s1转为字符数组
        char[] chs = s1.toCharArray();
        System.out.println(Arrays.toString(chs));
        //将字符串s1转为字节数组
        byte[] bs = s1.getBytes();
        System.out.println(Arrays.toString(bs));
        //将字符串转为字符串数组
        String[] ss = s1.split("-");
        System.out.println(Arrays.toString(ss));
        //替换字符串
        String s2 = s1.replace("word", "java");
        System.out.println(s2);
        //替换字符串正则表达式的子串
        String s3 = s1.replaceAll("\\d", "");
        System.out.println(s3);
        //从beginIndex指定的索引位置开始截取字符串
        String s4 = s1.substring(5);
        System.out.println(s4);
        //从beginIndex指定的索引位置开始截取字符串，截取到endIndex指定的索引位置（不包含endIndex）
        String s5 = s1.substring(5, 10);
        System.out.println(s5);
        //将java拼接到s1中
        String s6 = s1.concat("java");
        System.out.println(s6);
        //将字符串转为大写
        String s7 = s1.toUpperCase();
        System.out.println(s7);
        //将字符串转为小写
        String s8 = s1.toLowerCase();
        System.out.println(s8);
        //去掉字符串前后的空格
        String s9 = s1.trim();
        System.out.println(s9);
        //判断字符串是否为空
        boolean b = s1.isEmpty();
        System.out.println("b = " + b);
        //判断字符串是否相等
        boolean b1 = s1.equals("helloword");
        System.out.println("b1 = " + b1);
        //判断字符串是否相等，忽略大小写
        boolean b2 = s1.equalsIgnoreCase("helloword");
        System.out.println("b2 = " + b2);
        //比较两个字符串的大小关系
        int i = s1.compareTo("helloword");
        System.out.println("i = " + i);
        //忽略大小写比较两个字符串的大小关系
        i = s1.compareToIgnoreCase("helloword");
        System.out.println("i = " + i);
        //将int类型的值转为字符串
        String s10 = String.valueOf(123);
        System.out.println(s10);
    }
    public static void main1(String[] args) {
        String s1 = "hellowordhellowordhellowordefvefcvfdsdcslcfv";
        //获取字符串长度
        int len = s1.length();
        System.out.println("字符串长度为：" + len);
        //获取字符串中第3个字符
        char c = s1.charAt(2);
        System.out.println("第3个字符为：" + c);
        //从后往前查找'l'第一次出现的位置
        int index = s1.lastIndexOf('l');
        System.out.println("index = " + index);
        //从第4个字符开始，查找'l'第一次出现的位置
        index = s1.indexOf('l', 3);
        System.out.println("index = " + index);
        //判断字符串是否以"hello"开头
        boolean b = s1.startsWith("hello");
        System.out.println("b = " + b);
        //判断字符串是否以"word"结尾
        b = s1.endsWith("word");
        System.out.println("b = " + b);
        //判断字符串是否包含"word"
        b = s1.contains("word");
        System.out.println("b = " + b);
        //判断字符串是否为空
        b = s1.isEmpty();
        System.out.println("b = " + b);

    }
}
